/**
 * 
 * url:网络请求的url
 * params:发送的数据
 * success:成功的回调函数
 * fail：失败的回调
 * message:loading的提示信息（可选项）
 */

// const baseUrl = "http://47.104.237.150:8081/office"
// const imgUrl = "https://www.saramei.com/office/wx/upload/static-img/"
const baseUrl = "https://www.meetspace.cn/office"
const imgUrl = "https://www.meetspace.cn/office/wx/upload/static-img/"


const getOpenIdAPI = "/wx/wechat/query/openId" //获取openId
const advAPI = "/wx/advertising/list" //获取首页广告
const newsletterAPI = "/wx/newsletter/list" //获取活动公告
const visitorApplyAPI = "/wx/visitor/add"; //访客申请
const visitorListAPI = "/wx/visitor/list"; //访客列表
const visitorApproveAPI = "/wx/visitor/approve"; //访客申请
const meetingApplyAPI = "/wx/meeting/apply/add"; //会议申请
const meetingListAPI = "/wx/meeting/apply/list"; //会议列表
const meetingInfoAPI = "/wx/meeting/apply/info/list"; //会议信息列表，查询某个会议室的占用情况
const meetingCancelAPI = "/wx/meeting/apply/cancel"; //取消会议
const couponsAPI = '/wx/meeting/apply/coupons';
const problemAddAPI = "/wx/problem/add"; //报事报修
const problemListAPI = "/wx/problem/list"; //报事报修查询
const meetingRoomListAPI = "/wx/meeting/apply/meetingroom"; //会议室列表
const memRegisterAPI = "/wx/member/register"; //会员注册
const authAPI = "/wx/auth/login" //判断用户是否注册
const noticeListAPI = "/wx/notice/list" //通知列表查询 
const surveyApplyAPI = "/wx/satisficing/add" //满意度调查
const announceAPI = "/wx/applet/list" //新闻资讯
const environmentAPI = "/wx/environment/info" //环境监测
const msgAPI = "/wx/notice" //消息通知
const msgReadAPI = '/wx/notice/read' //设置消息已读
const qrCodeAPI = '/wx/visitor/temporary/qr' //临时通行二维码
const questionListAPI = '/wx/satisficing/question/list'
const questionAddAPI = '/wx/satisficing/question/add'
const doorListAPI = '/wx/door/list' //获取门禁列表
const doorOpenAPI = '/wx/door/open'




function httpRequest(url, data = {}, method = 'post') {
  url = baseUrl + url;
  return new Promise((resolve, reject) => {
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json' // 设置请求的 header
      },
      success: function (res) {
        if (res.statusCode === 200) {
          resolve(res.data); // 请求成功，返回数据
        } else {
          reject({
            code: res.statusCode,
            message: '请求失败'
          }); // 请求失败
        }
      },
      fail: function (error) {
        reject({
          code: -1,
          message: '网络错误'
        }); // 网络错误
      }
    });
  });
}
module.exports = {
  getOpenIdAPI: getOpenIdAPI,
  httpRequest: httpRequest,
  visitorApplyAPI: visitorApplyAPI,
  problemAddAPI: problemAddAPI,
  problemListAPI: problemListAPI,
  meetingRoomListAPI: meetingRoomListAPI,
  meetingApplyAPI: meetingApplyAPI,
  meetingListAPI: meetingListAPI,
  meetingCancelAPI: meetingCancelAPI,
  visitorListAPI: visitorListAPI,
  memRegisterAPI: memRegisterAPI,
  imgUrl: imgUrl,
  noticeListAPI: noticeListAPI,
  surveyApplyAPI: surveyApplyAPI,
  announceAPI: announceAPI,
  visitorApproveAPI: visitorApproveAPI,
  environmentAPI: environmentAPI,
  msgAPI: msgAPI,
  authAPI: authAPI,
  baseUrl: baseUrl,
  couponsAPI: couponsAPI,
  msgReadAPI: msgReadAPI,
  advAPI: advAPI,
  qrCodeAPI: qrCodeAPI,
  questionListAPI: questionListAPI,
  questionAddAPI: questionAddAPI,
  newsletterAPI: newsletterAPI,
  doorListAPI: doorListAPI,
  doorOpenAPI: doorOpenAPI,
  meetingInfoAPI: meetingInfoAPI
}